package com.orange.controller;

import java.util.HashMap;
import java.util.Map;

import net.sf.json.JSONObject;

import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
//import org.apache.log4j.Logger;


@Controller
public class BaseController {
	
	//private static final Logger logger = Logger.getLogger(BaseController.class);

	/**
	 * 
	 * @param o
	 * @param code
	 * @param errorMsg
	 * @return
	 */
	public  static ResponseEntity<String> toResponse(Object o,String code,String errorMsg){
		
		if(null==o){
			o="0";
		}
		if(null==code){
			code="000000";
		}
		if(null==errorMsg){
			errorMsg="0";
		}
		Map<String, Object> map=new HashMap<String, Object>();
		map.put("code", code);
		map.put("errorMsg", errorMsg);
		map.put("data", o);
		JSONObject jsonObject = JSONObject.fromObject(map);
		return new ResponseEntity<String>(jsonObject.toString(),HttpStatus.OK);
		
	}
}
